package com.ejemplos;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;
import android.widget.Toast;

public class SettingsActivity extends PreferenceActivity {

	
	@SuppressWarnings("deprecation")
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.settings);
        
        Preference configCheckbox = (Preference) findPreference("config_checkbox_value");
        configCheckbox.setOnPreferenceClickListener(new OnPreferenceClickListener() {
	         public boolean onPreferenceClick(Preference preference) {
	            
	        	SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(SettingsActivity.this);
	        	Boolean checkbox = preferences.getBoolean("config_checkbox", false);
	        	Toast.makeText(SettingsActivity.this, "config_checkbox : " + checkbox, Toast.LENGTH_SHORT).show();
	        	 
	        	return true;
	         }
	    });
        
        Preference configText = (Preference) findPreference("config_text_value");
        configText.setOnPreferenceClickListener(new OnPreferenceClickListener() {
	         public boolean onPreferenceClick(Preference preference) {
	            
	        	SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(SettingsActivity.this);
	        	String text = preferences.getString("config_text", "");
	        	Toast.makeText(SettingsActivity.this, "config_text : " + text, Toast.LENGTH_SHORT).show();
	        	 
	        	return true;
	         }
	    });
    }
}